﻿<UserControl
    x:Class="Markup.Programming.Samples.AllSamples"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:p="http://markupprogramming.codeplex.com/markup/programming"
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:samples="clr-namespace:Markup.Programming.Samples"
    mc:Ignorable="d" 
    d:DesignHeight="500" d:DesignWidth="500">
    <UserControl.Resources>
        <p:ResourceCollection x:Key="UserControls">
            <samples:HelloWorld/>
            <samples:TowerOfHanoi/>
            <samples:Calculator/>
            <samples:CallingChoices/>
            <samples:SelectOnFocus/>
            <samples:ForLoops/>
            <samples:DynamicButton/>
            <samples:PasswordSample/>
            <samples:ResourceObjectSample/>
            <samples:StateSample/>
            <samples:CrashSample/>
        </p:ResourceCollection>
        <p:ResourceObject x:Key="ViewModel">
            <p:Property PropertyName="Samples">
                <p:Iterator>
                    <p:ForEach Var="$userControl" Value="{StaticResource UserControls}">
                        <p:Yield>
                            <p:Object>
                                <p:Property PropertyName="Name" Path="$userControl.ToString()"/>
                                <p:Property PropertyName="Control" Path="$userControl"/>
                            </p:Object>
                        </p:Yield>
                    </p:ForEach>
                </p:Iterator>
            </p:Property>
        </p:ResourceObject>
    </UserControl.Resources>
    <Grid DataContext="{Binding Value, Source={StaticResource ViewModel}}">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <TextBlock Text="Markup Programming Samples" FontSize="20"/>
        <ComboBox ItemsSource="{Binding Samples}" Grid.Row="1">
            <p:Attached.Operations>
                <p:ScriptHandler Path="SelectionChanged">
                    var $children = @FindElement("ContentHost").Children;
                    $children.Clear();
                    $children.Add(Samples[@AssociatedObject.SelectedIndex].Control);
                </p:ScriptHandler>
            </p:Attached.Operations>
            <ComboBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Name}"/>
                </DataTemplate>
            </ComboBox.ItemTemplate>
        </ComboBox>
        <Grid Name="ContentHost" Grid.Row="2" Background="SlateGray"/>
    </Grid>
</UserControl>
